package com.llkj.qingnianguoxue.adapter;

import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.bean.PreviousActionBean;
import com.llkj.qingnianguoxue.util.DisplayUtil;
import com.llkj.qingnianguoxue.util.ImageLoadingUtil;

import java.util.List;

/**
 * 往期活动
 */
public class PreviousActionAdapter extends BaseQuickAdapter<PreviousActionBean.ActionBean, BaseViewHolder> {

    private boolean mIsFee = false;

    public PreviousActionAdapter(int layoutResId, List<PreviousActionBean.ActionBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, PreviousActionBean.ActionBean item) {
        ImageView ivPic = baseViewHolder.getView(R.id.iv_action_pic);
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) ivPic.getLayoutParams();
        params.height = DisplayUtil.getDensityWdith(mContext)*9/16;

        ImageLoadingUtil.loadingUrl(ivPic, item.getActivityimg());
        baseViewHolder.setText(R.id.tv_title, item.getName());
        baseViewHolder.setText(R.id.tv_money, String.format(mContext.getString(R.string.book_course_price),item.getPrice()));
        baseViewHolder.setText(R.id.tv_address, "地点："+item.getSite());
        if(mIsFee){
            baseViewHolder.setVisible(R.id.tv_money,false);
        }

        TextView tvState = baseViewHolder.getView(R.id.tv_state);
        //1 未报名 2 已报名 3 已结束
        if (PreviousActionBean.ActionBean.ACTION_BOOKING.equals(item.getStatus())) {
            tvState.setText("报名中");
            tvState.setSelected(false);
        } else if (PreviousActionBean.ActionBean.ACTION_BOOKED.equals(item.getStatus())) {
            tvState.setText("已报名");
            tvState.setSelected(true);
        } else if (PreviousActionBean.ActionBean.ACTION_COMPLETED.equals(item.getStatus())) {
            tvState.setText("已结束");
            tvState.setSelected(true);
        }
    }

    public void setIsFee(boolean isFee){
        mIsFee = isFee;
    }

    private void setTextColor(TextView tv, int type) {
        if (type == 1) {
            tv.setTextColor(mContext.getResources().getColor(R.color.colorB93A3C));
        }else if (type == 2) {
            tv.setTextColor(mContext.getResources().getColor(R.color.color71D49C));
        } else {
            tv.setTextColor(mContext.getResources().getColor(R.color.color999999));
        }
    }
}
